(function (doc) {
  const oReault = doc.getElementsByClassName("result")[0];
  const oInputs = doc.getElementsByTagName("input");
  const oButton = doc.getElementsByClassName("btn-group")[0];
  function init() {
    oButton.addEventListener("click", btnClick, false);
  }
  function btnClick(ev) {
    const e = ev || window.event,
      tar = e.target || e.srcElement,
      tarNames = tar.tagName.toLowerCase();
    console.log(window.event);
    console.log(tar.tagName);
    if (tarNames === "button") {
      const input1 = Number(oInputs[0].value),
        input2 = Number(oInputs[1].value),
        method = tar.getAttribute("data-field");
      renderResult(compute(method, input1, input2));
    }
  }
  function renderResult(result) {
    oReault.innerHTML = result;
  }
  function compute(method, val1, val2) {
    switch (method) {
      case "plus":
        return val1 + val2;
      case "minus":
        return val1 - val2;
      case "mul":
        return val1 * val2;
      case "div":
        return val1 / val2;
      default:
        break;
    }
  }
  init();
})(document);
